package edu.sctu.lab03;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class UserListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response)
            throws ServletException, IOException {
        //快速删除一行ctrl+x
        //换行shift+enter
        //  resp.setHeader("content-type","text/html;" +
        //    "charset=UTF-8");//这行代码解决中文乱码问题
        // 1. 查数据库并且得到userList
        Database database = new Database();
        List<User> userList = database.getUserList();

        // 2. request空间中新建一个名为userList的变量
        request.setAttribute("userList", userList);


        // 3. 跳转到userList.jsp页面
        request.getRequestDispatcher("/userList.jsp")
                .forward(request, response);

    }
}
//JSP的路径是固定的，Servlet路径可以自己配置，
// 在<url-pattern>   </url-pattern>中配置
//JSP更适合写java代码